﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CMS.BLL;

public partial class ContactUs : System.Web.UI.Page
{
    int nCurrentLanguage = Support.GetCurrentLanguage();
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack){
            this.SetLabel();
        }
    }
    private void SetLabel()
    {
        lblEmail.Text = MultipleLanguage.EMAIL[nCurrentLanguage - 1];
        lblfullName.Text = MultipleLanguage.FULLNAME[nCurrentLanguage - 1];
        lblContents.Text = MultipleLanguage.CONTENT[nCurrentLanguage - 1];
        lblPhone.Text = MultipleLanguage.TELEPHONE[nCurrentLanguage - 1];
        lbtSend.Text = MultipleLanguage.SEND[nCurrentLanguage - 1];

        Company objCompany = new Company();
        DataTable dtbCompany = new DataTable();
        dtbCompany = objCompany.Search();
        int nCompanyCount = dtbCompany.Rows.Count;
        int nCompanyLastestID = ConvertData.ConvertToInt(dtbCompany.Rows[nCompanyCount - 1]["CompanyID"]);
        objCompany.LoadById(nCompanyLastestID);
        switch (nCurrentLanguage)
        {
            case 1:
                
                lblCompanyName.Text = objCompany.Data.CompanyName1.ToUpper();
                lblHeadOfficeAdd.Text = objCompany.Data.Address1;
                break;
            case 2:
                lblCompanyName.Text = objCompany.Data.CompanyName2.ToUpper();
                lblHeadOfficeAdd.Text = objCompany.Data.Address2;
                break;
            case 3:
                lblCompanyName.Text = objCompany.Data.CompanyName3.ToUpper();
                lblHeadOfficeAdd.Text = objCompany.Data.Address3;
                break;
        }

        lblHeadOfficeEmail.Text = objCompany.Data.Email;
        lblHeadOfficeTel.Text = objCompany.Data.Tel;
    }

    private void ClearForm()
    {
        txtEmail.Text = string.Empty;
        txtFullName.Text = string.Empty;
        txtContent.Text = string.Empty;
        txtPhone.Text = string.Empty;
    }
    protected void lbtSend_Click(object sender, EventArgs e)
    {
        Contacts objContact = new Contacts();
        objContact.Data.Email = ConvertData.ConvertToString(txtEmail.Text.Trim());
        objContact.Data.Telephone = ConvertData.ConvertToString(txtPhone.Text.Trim());
        objContact.Data.Fullname = ConvertData.ConvertToString(txtFullName.Text.Trim());
        objContact.Data.MainContent = ConvertData.ConvertToString(txtContent.Text.Trim());
        objContact.Data.Status = 0;
        objContact.Data.CreatedDate = ConvertData.ConvertDatetimeToInt(DateTime.Today);

        int nResult = objContact.Insert();
        int iCurrentLang = Support.GetCurrentLanguage();
        if (nResult > 0)
        {
            ClearForm();
            MessageBoxss.Show(MultipleLanguage.CONTACT_SENT[iCurrentLang - 1]);
            
        }
        else { MessageBoxss.Show(MultipleLanguage.CONTACT_SEND_FAIL[iCurrentLang - 1]); }
    }
}